/* 
 *   Date       Developer   Description
 *   
 *
 *   Classname:  example.console.SystemConsoleMain
 * 
 *   Date:   2014-3-3
 * 
 *   The source code contained in this listing is proprietary to
 *   HLJ POST YITONG INFO-NET CO.,LTD.
 * 
 *   Unauthorized copying, adaptation, distribution, use, or display
 *   is strictly prohibited.
 *   This software is Copyright 2014 HLJ POST YITONG INFO-NET CO.,LTD.
 */
package com.titan.demo.camel.sample.console;

import java.io.InputStream;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.main.Main;
import org.apache.camel.model.RouteDefinition;
import org.apache.commons.io.IOUtils;



/**
 *
 *
 * @author Administrator
 *
 */
public class SystemConsoleMain {
    private final static String encoding = "GB2312";
    
    public static void main(String[] args) {
        try {
            Main main = new Main();

            main.addRouteBuilder(
                new RouteBuilder() {
                    public void configure() {
                        RouteDefinition rd = from("stream:in?promptMessage=Enter something: &encoding="+encoding);
                        rd = rd.process(new Processor() {
                            public void process(Exchange exchange) throws Exception {
                                InputStream input = exchange.getIn().getBody(InputStream.class);
                                String inputString = IOUtils.toString(input, encoding);
                                System.out.println("输入："+inputString);
                            }
                        });
                        rd.to("stream:out");
                    }
                }
            );
            main.run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

